#!/bin/bash

[ ${ROTATE} ] || exit 0

MVOPTS=" -f -v -u"

case $TIPO in
completo)
	echo "Rotando backups ..."
	
	for i in $(seq ${ROTATE} -1 1)
	do
		[ ! -d ${ROOT}/semana-${i} ] && mkdir ${ROOT}/semana-${i}
		case $i in
		1)
			[ -f ${ROOT}/*.tar${ZIP:+.gz} ] &&  mv ${MVOPTS} ${ROOT}/*.tar${ZIP:+.gz} ${ROOT}/semana-1/
			;;
		*)
			if [ -f ${ROOT}/semana-$((${i}-1))/*.tar${ZIP:+.gz} ];then
				  mv ${MVOPTS} ${ROOT}/semana-$((${i}-1))/*.tar${ZIP:+.gz} ${ROOT}/semana-$((${i}))/
			fi
			;;

		esac
	done

	;;
*)
esac

exit 0
